<template>
  <el-collapse-item v-if="enable" :name="name">
    <template #title>
        <span style="padding-left:20px">
          流转条件<el-icon class="header-icon"><info-filled /></el-icon>
        </span>
     </template>
        <Conditional
         :element="element"
          :bpmnModeler="bpmnModeler"
        />
        
  </el-collapse-item>
</template>
<script>
import Conditional from './parts/Conditional.vue'
import eventDefinitionHelper from 'jp-bpmn-js-properties-panel/lib/helper/EventDefinitionHelper'
import { is } from 'jeeplus-bpmn/lib/util/ModelUtil'
import { getBusinessObject } from 'jeeplus-bpmn/lib/util/ModelUtil'
import { isAny } from 'jeeplus-bpmn/lib/features/modeling/util/ModelingUtil'
export default {
  components: {
    Conditional
  },
  props: {
    element: {
      type: Object,
      default: undefined
    },
    bpmnModeler: {
      type: Object,
      default: undefined
    },
    name: ''
  },
  computed: {
    enable () {
      if (this.element && getBusinessObject(this.element)) {
        let conditionalEventDefinition = eventDefinitionHelper.getConditionalEventDefinition(this.element)
        if (!(is(this.element, 'bpmn:SequenceFlow') && this.isConditionalSource(this.element.source)) &&
    !conditionalEventDefinition) {
          return false
        } else {
          return true
        }
      } else {
        return false
      }
    }
  },
  methods: {

    isConditionalSource (element) {
      let CONDITIONAL_SOURCES = [
        'bpmn:Activity',
        'bpmn:StartEvent',
        'bpmn:ExclusiveGateway',
        'bpmn:InclusiveGateway',
        'bpmn:ComplexGateway'
      ]

      return isAny(element, CONDITIONAL_SOURCES)
    }
  }
}
</script>